<link rel="stylesheet" href="assets/user/css/goods.css">
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-sm12 layui-col-md12 layui-col-lg12">
			<div class="widget-head">
				<div class="widget-title layer-cf">添加商品</div>
			</div>
			<form id="my-form" class="layer-form tpl-form-line-form" method="post">
				<div class="widget-body layui-col-lg12">
					<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
						<ul class="layui-tab-title">
							<li class="layui-this">基础设置</li>
							<li>商品相册</li>
							<li>商品详情</li>
							<li>商品规格</li>
							<li>商品属性</li>
						</ul>
						<div class="layui-tab-content">
							<div class="layui-tab-item layui-show">
								<div class="layer-form-group">
									<label class="layui-form-label form-require">商品名称：</label>
									<div class="layui-col-sm7  layer-midd-left">
										<input type="text" class="tpl-form-input" name="goods[goods_name]" value="{$goodsInfo['goods_name'] ?? ''}" required>
									</div>
								</div>
								<div class="layer-form-group">
									<label class="layui-form-label form-require">商品简介：</label>
									<div class="layui-col-sm7  layer-midd-left">
										  <textarea rows="3" cols="50" name="goods[goods_remark]">{$goodsInfo['goods_remark']??''}</textarea>
									</div>
								</div>
								<div class="layer-form-group">
									<label class="layui-form-label form-require">商品分类： </label>
									<div class="layui-col-sm2 layer-midd-left" style="margin-right:15px;">
										 <input type="text" id="tree"  name="goods[cat_id]" value=""  lay-filter="tree" class="layui-input">
									    
									</div>
									<div class="layui-col-sm2 layer-midd-left">
										<a href="{:url('user/item/editcategory')}" class="layui-btn layui-btn-sm">去添加</a>
									</div>
									
								</div>
								
								<div class="layer-form-group">
									<label class="layui-form-label form-require">商品品牌： </label>
									<div class="layui-col-sm2  layer-midd-left">
										<select  id="parent_id_1"  name="goods[brand_id]"
												data-am-selected="{searchBox: 1, btnSize: 'sm'}">
											<option value="0">顶级分类</option>
											{volist name="brandList" id="brand"}
												<option {if condition="$brand['id'] eq $goodsInfo['brand_id'] "}selected="selected" {/if} value="{$brand['id']??''}">
													{$brand['name']??''}</option>
												{/volist}
											
										</select>										
									</div>
										<div class="layui-col-sm2 layer-midd-left">
											<a href="{:url('user/item/savebrand')}" class="layui-btn layui-btn-sm">去添加</a>
										</div>
								
								</div>
								<div class="layer-form-group">
									<label class="layui-form-label form-require">运费模板： </label>
									<div class="layui-col-sm2  layer-midd-left">
										<select name="goods[delivery_id]" required
												data-layer-selected="{searchBox: 1, btnSize: 'sm',  placeholder:'请选择运费模板'}">
											<option value="">请选择运费模板</option>
											{volist name="delivery" id="item"}
												<option {if condition="$item['delivery_id'] eq $goodsInfo['delivery_id'] "}selected="selected"{/if} value="{$item['delivery_id']??''}">
													{$item['name']} ({$item['method']['text']})
												</option>
											{/volist}
										</select>
									</div>
										<div class="layui-col-sm2 layer-midd-left">
											<a href="{:url('user/setting/edit')}" class="layui-btn layui-btn-sm">去添加</a>
										</div>
								</div>
								
							
					
								<div class="layer-form-group">
									<label class="layui-form-label form-require">赠送积分：</label>
									<div class="layui-col-sm7  layer-midd-left">
										<input type="text" class="tpl-form-input"  name="goods[give_integral]"
											   value="{$goodsInfo['give_integral']?? 0}" required>
									</div>
								</div>
									
								<div class="layer-form-group">
									<label class="layui-form-label form-require">初始销量：</label>
									<div class="layui-col-sm7  layer-midd-left">
										<input type="text" class="tpl-form-input" name="goods[sales_initial]"
											   value="{$goodsInfo['sales_initial']??''}" required>
									</div>
								</div>
								<div class="layer-form-group">
									<label class="layui-form-label form-require">分佣方式：</label>
									 <div class="layui-col-sm2 layer-midd-left">
									  <select name="goods['agent_type']" lay-verify="required">
										<option value="1" {if $goodsInfo['agent_type']==1}checked {/if}>百分比</option>
										<option value="2" {if $goodsInfo['agent_type']==2}checked {/if} >固定</option>
									  </select>
									</div>
									<div class="layui-col-sm3 layer-midd-left">
										<input type="text" class="tpl-form-input"  name="goods[agent_price]"
											   value="{$goodsInfo['agent_price']?? ''}" placeholder="请输入分佣比例" required>
									</div>
								</div>
							
							</div> 
					
							<div class="layui-tab-item">    
								<div class="layer-form-group">
									<label class="layui-form-label form-require">商品图片： </label>
									<div class="layui-col-sm7  layer-midd-left">
										<div class="layer-form-file">
											<div class="layer-form-file">
												<button type="button"
														class="j-withdraw_apply  layui-btn layer-btn-secondary layer-radius">
													<i class="layer-icon-cloud-upload"></i> 选择图片
												</button>
												<div class="uploader-list layer-cf">
													{if isset($goodsInfo.image)}
													{foreach $goodsInfo.image as $image}
														<div class="file-item">
															<a href="{$image['file_path']}"
															   title="点击查看大图"
															   target="_blank">
																<img src="{$image['file_path']}">
															</a>
															<input type="hidden"
																   name="goods[goods_images][]"
																   value="{$image['image_id']??''}">
															<i class="mdi menu-icon mdi-window-close file-item-delete"></i>
														</div>
												{/foreach}
												{/if}
												</div>
											</div>
											<div class="help-block">
												<small>尺寸：宽750像素 高度不限</small>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="layui-tab-item">
								 
								<div class="layer-form-group">
									<label class="layui-form-label form-require">商品详情： </label>
									<div class="layui-col-sm7  layer-midd-left">
									
										<textarea id="container" name="goods[goods_content]" type="text/plain">
										{$goodsInfo['goods_content']}
										</textarea>
									</div>
								</div>
						
							</div>
							<div class="layui-tab-item">
								<div class="layer-form-group">
									<label class="layui-form-label form-require">商品类型： </label>
									<div class="layer-u-sm-7 layer-midd-left">
										<select name="goods[spec_type]" id="spec_type">
										<option value="0">顶级分类</option>
										
										{if isset($itemType)}{foreach ($itemType as $type)}
											<option {if condition="$goodsInfo['spec_type'] eq $type['id']"} selected="selected" {/if} value="{$type['id']??''}">
												
												{$type['name']}</option>
											{/foreach}{/if}
												
										</select>
									</div>
								</div>
								<div id="ajax_spec_data">
								<!-- ajax 返回规格--></div>
							</div>
							<div class="layui-tab-item">
								<table class="table table-bordered attr" id="goods_attr_table" style="width:80%;">

								</table>
							</div>
						</div>
					</div>
					<div class="layer-form-group">
						<div class="layui-col-sm7  layer-u-sm-push-3 layer-margin-top-lg">
							 <input type="hidden"  class="goodsid" name="goods[goods_id]" value="{$goodsInfo.goods_id}">
							 <input type="hidden"  value="{$goodsInfo['cat_id']??''}"  lay-filter="tree" class="layui-input catid">
							<button type="submit" class="j-submit layui-btn layer-btn-secondary">提交
							</button>
						</div>
					</div>
				</div>
            </form>
        </div>
    </div>
</div>
<!-- 图片文件列表模板 -->

<!-- 文件库弹窗 -->
{include file="layouts/_template/file_library" /}
{include file="item/_template/spec_many" /}
<script src="assets/user/js/goods.spec.js"></script>
<script>
var cat_id="{$goodsInfo['cat_id']??''}";
</script>
<script src="assets/user/js/goods.category.js"></script>
<script>
		$(function () {
			  // 富文本编辑器
		layui.use('layedit', function(){
		var layedit = layui.layedit;
		layedit.build('container', {
		height: 600, //设置编辑器高度
		uploadImage: {
                    url: '/index.php?s=/user/upload/upload' //接口url
                  , type: 'post' //默认post
                }
		});	
		});
		
        // 选择图片
        $('.j-withdraw_apply').selectImages({
            name: 'goods[goods_images][]'
            , multiple: true
        });
		 //地址的定位
		layui.use('element', function(){
			var $ = layui.jquery
			,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
			
		});
        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();
    });
	
</script>
<script>
//先执行规格
	var goods_id = '{$goodsInfo.goods_id}';
	var spec_type  = '{$goodsInfo.spec_type}';
	if(goods_id){
	
		spec(spec_type);
		goodstype(goods_id,spec_type);
	}
	
</script>